package com.web.dao;

import com.web.entity.SysMenu;
import com.web.entity.SysMenuExample;
import java.util.List;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

/**
 * @author FDjavaone
 */
public interface SysMenuMapper {
    @SelectProvider(type=SysMenuSqlProvider.class, method="countByExample")
    int countByExample(SysMenuExample example);

    @DeleteProvider(type=SysMenuSqlProvider.class, method="deleteByExample")
    int deleteByExample(SysMenuExample example);

    @Delete({
        "delete from t_sys_menu",
        " where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into t_sys_menu (text, url, ",
        " level, icon, pid, ",
        " sort, perm, has_next, ",
        " enabled, description)",
        " values (#{text,jdbcType=VARCHAR}, #{url,jdbcType=VARCHAR}, ",
        " #{level,jdbcType=INTEGER}, #{icon,jdbcType=VARCHAR}, #{pid,jdbcType=BIGINT}, ",
        " #{sort,jdbcType=INTEGER}, #{perm,jdbcType=VARCHAR}, #{hasNext,jdbcType=BIT}, ",
        " #{enabled,jdbcType=BIT}, #{description,jdbcType=VARCHAR})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insert(SysMenu record);

    @InsertProvider(type=SysMenuSqlProvider.class, method="insertSelective")
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Long.class)
    int insertSelective(SysMenu record);

    @SelectProvider(type=SysMenuSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="text", property="text", jdbcType=JdbcType.VARCHAR),
        @Result(column="url", property="url", jdbcType=JdbcType.VARCHAR),
        @Result(column="level", property="level", jdbcType=JdbcType.INTEGER),
        @Result(column="icon", property="icon", jdbcType=JdbcType.VARCHAR),
        @Result(column="pid", property="pid", jdbcType=JdbcType.BIGINT),
        @Result(column="sort", property="sort", jdbcType=JdbcType.INTEGER),
        @Result(column="perm", property="perm", jdbcType=JdbcType.VARCHAR),
        @Result(column="has_next", property="hasNext", jdbcType=JdbcType.BIT),
        @Result(column="enabled", property="enabled", jdbcType=JdbcType.BIT),
        @Result(column="description", property="description", jdbcType=JdbcType.VARCHAR)
    })
    List<SysMenu> selectByExample(SysMenuExample example);

    @Select({
        "select",
        " id, text, url, level, icon, pid, sort, perm, has_next, enabled, description",
        " from t_sys_menu",
        " where id = #{id,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="text", property="text", jdbcType=JdbcType.VARCHAR),
        @Result(column="url", property="url", jdbcType=JdbcType.VARCHAR),
        @Result(column="level", property="level", jdbcType=JdbcType.INTEGER),
        @Result(column="icon", property="icon", jdbcType=JdbcType.VARCHAR),
        @Result(column="pid", property="pid", jdbcType=JdbcType.BIGINT),
        @Result(column="sort", property="sort", jdbcType=JdbcType.INTEGER),
        @Result(column="perm", property="perm", jdbcType=JdbcType.VARCHAR),
        @Result(column="has_next", property="hasNext", jdbcType=JdbcType.BIT),
        @Result(column="enabled", property="enabled", jdbcType=JdbcType.BIT),
        @Result(column="description", property="description", jdbcType=JdbcType.VARCHAR)
    })
    SysMenu selectByPrimaryKey(Long id);

    @UpdateProvider(type=SysMenuSqlProvider.class, method="updateByExampleSelective")
    int updateByExampleSelective(@Param("record") SysMenu record, @Param("example") SysMenuExample example);

    @UpdateProvider(type=SysMenuSqlProvider.class, method="updateByExample")
    int updateByExample(@Param("record") SysMenu record, @Param("example") SysMenuExample example);

    @UpdateProvider(type=SysMenuSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(SysMenu record);

    @Update({
        "update t_sys_menu",
        " set text = #{text,jdbcType=VARCHAR},",
          " url = #{url,jdbcType=VARCHAR},",
          " level = #{level,jdbcType=INTEGER},",
          " icon = #{icon,jdbcType=VARCHAR},",
          " pid = #{pid,jdbcType=BIGINT},",
          " sort = #{sort,jdbcType=INTEGER},",
          " perm = #{perm,jdbcType=VARCHAR},",
          " has_next = #{hasNext,jdbcType=BIT},",
          " enabled = #{enabled,jdbcType=BIT},",
          " description = #{description,jdbcType=VARCHAR}",
        " where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(SysMenu record);


    @Update("update t_sys_menu set enabled=#{enabled} where id=#{id}")
    int enableById(@Param("id") Long id,@Param("enabled") Boolean enabled);

    @Select("select * from t_sys_menu where pid=#{pid}")
    List<SysMenu> selectByPid(@Param("pid") Long pid);

    @Update("update t_sys_menu set has_next=#{hasNext} where id=#{id}")
    int updateHasNext(@Param("id") Long id,@Param("hasNext")Boolean hasNext);

    @Select("SELECT sym.*,tp.id as `permission.id`,tp.text as `permission.text`,tp.perm as `permission.perm` from t_sys_menu sym LEFT JOIN t_permission tp on sym.id=tp.menu_id")
    @ResultMap("BaseResultMap")
    List<SysMenu> selectPermissonByExample();

}